//
//  GoodsTableViewCell.m
//  xingfugangwan
//
//  Created by rainday on 14/12/18.
//  Copyright (c) 2014年 rainday. All rights reserved.
//

#import "GoodsTableViewCell.h"
#import "XFGWCart.h"


@implementation GoodsTableViewCell

- (void)awakeFromNib {
    // Initialization code
    _numberLabel.layer.borderWidth = 2.0;
    _numberLabel.layer.borderColor = [[UIColor lightGrayColor]CGColor];
    
    [_selectedButton setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [_selectedButton setImage:[UIImage imageNamed:@"已选中"] forState:UIControlStateSelected];
    
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)doSelect:(id)sender{
    UIButton *button = (UIButton *)sender;
    button.selected = !button.selected;
    XFGWCart *cart = [XFGWCart shareCart];
    if(button.selected)
    {
        
        
        [cart.dictionary setObject:_numberLabel.text forKey:_nameLabel.text];
            
        
        
    }else{
        
        [cart.dictionary removeObjectForKey:_nameLabel.text];
        
    }
    NSLog(@"%@",cart.dictionary);
}

- (void)addOrLess:(id)sender
{
    UIButton *button = (UIButton *)sender;
    if (button.tag==9000) {
        
        NSString *string = _numberLabel.text;
        int number = [string intValue];
        if (number>1) {
            number -=1;
        }
        _numberLabel.text = [NSString stringWithFormat:@"%i",number];
        
//        --
    }
    
    if (button.tag==9001) {
//        ++
        NSString *string = _numberLabel.text;
        int number = [string intValue];
        number +=1;
        if (number>99) {
            number=99;
        }
        _numberLabel.text = [NSString stringWithFormat:@"%i",number];

    }
    
    XFGWCart *cart = [XFGWCart shareCart];
    [cart.dictionary setObject:_numberLabel.text forKey:_nameLabel.text];
    NSLog(@"%@",cart.dictionary);

}

@end
